-- Random settings limits: index_granularity=(100, 60000); index_granularity_bytes=(10000, None)
-- Tags: long

SET enable_json_type = 1;
set max_block_size = 20000;

drop table if exists test;

{% for create_command in ['create table test (x UInt64, json String) engine=MergeTree order by x settings min_rows_for_wide_part=100000000, min_bytes_for_wide_part=1000000000;',
                          'create table test (x UInt64, json String) engine=MergeTree order by x settings min_rows_for_wide_part=1, min_bytes_for_wide_part=1;'] -%}

{{ create_command }}

insert into test select number, toJSONString(map('key' || multiIf(number < 60000, number % 2, number < 120000, number % 2 + 2, number % 2 + 4), 'value' || number)) from numbers(200000);

alter table test modify column json JSON settings mutations_sync=1;

select 'All paths:';
select distinctJSONPaths(json) from test;
select 'Shared data paths:';
select distinct (arrayJoin(JSONSharedDataPaths(json))) as path from test order by path;
select json from test order by x limit 10;
select json from test order by x limit 10 offset 60000;
select json from test order by x limit 10 offset 120000;
select json.key0, json.key1, json.key2, json.key3, json.key4, json.key5 from test order by x limit 10;
select json.key0, json.key1, json.key2, json.key3, json.key4, json.key5 from test order by x limit 10 offset 60000;
select json.key0, json.key1, json.key2, json.key3, json.key4, json.key5 from test order by x limit 10 offset 120000;

select json from test format Null;
select json from test order by x format Null;
select json.key0, json.key1, json.key2, json.key3, json.key4, json.key5 from test format Null;
select json.key0, json.key1, json.key2, json.key3, json.key4, json.key5 from test order by x format Null;

drop table test;

{% endfor -%}
